/*
 * CompareGUI.java
 *
 * Created on 06 Kasım 2008 Perşembe, 16:36
 */
package org.testis.gui.mvc.view.testdesign;

import org.testis.gui.mvc.view.*;
import org.testis.gui.mvc.controller.testdesign.CompareGUIController;
import org.testis.gui.mvc.controller.TestDesignControllerList;
import org.testis.gui.mvc.utilities.ComparisonTreeNode;
import org.testis.gui.mvc.utilities.MyTreeRenderer;
import org.testis.utils.tree.MyDefaultMutableTreeNode;
import java.awt.Frame;
import java.awt.event.MouseEvent;
import java.awt.event.WindowListener;
import java.beans.PropertyChangeEvent;
import java.util.Enumeration;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JTree;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

/**
 *
 * @author  emir
 */
public class CompareGUI extends AtofBaseDialog implements AbstractViewPanel {

    private static final long serialVersionUID = 59322L;
    private ComparisonTreeNode m_sourceRoot = null;
    private ComparisonTreeNode m_destinationRoot = null;

    public CompareGUI(Frame displayFrame,
            boolean b,
            ComparisonTreeNode sourceRoot,
            ComparisonTreeNode destinationRoot) {
        super(displayFrame,
                b);
        m_sourceRoot = sourceRoot;
        m_destinationRoot = destinationRoot;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        sourceTree = new JTree(m_sourceRoot);
        jLabel1 = new javax.swing.JLabel();
        jSplitPane2 = new javax.swing.JSplitPane();
        jPanel2 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        singleModeButton = new javax.swing.JRadioButton();
        multipleModeButton = new javax.swing.JRadioButton();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        removeOperationButton = new javax.swing.JButton();
        addOperationsButton = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        propertyPane = new javax.swing.JTextPane();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        destinationTree = new JTree(m_destinationRoot);
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Compare Trees"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jSplitPane1.setDividerLocation(300);

        sourceTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        sourceTree.putClientProperty("JTree.lineStyle", "Angled");
        sourceTree.setCellRenderer(new MyTreeRenderer());
        sourceTree.setRootVisible(false);
        sourceTree.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                sourceTreeMouseClicked(evt);
            }
        });
        sourceTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                sourceTreeValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(sourceTree);

        jLabel1.setText("jLabel1"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 506, Short.MAX_VALUE))
        );

        jSplitPane1.setLeftComponent(jPanel1);

        jSplitPane2.setDividerLocation(243);

        jButton2.setText("OK"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Cancel"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        singleModeButton.setSelected(true);
        singleModeButton.setText("Single"); // NOI18N
        singleModeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                singleModeButtonActionPerformed(evt);
            }
        });

        multipleModeButton.setText("Multiple"); // NOI18N
        multipleModeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                multipleModeButtonActionPerformed(evt);
            }
        });

        jRadioButton1.setSelected(true);
        jRadioButton1.setText("Clone"); // NOI18N
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        jRadioButton2.setText("Copy"); // NOI18N
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        ImageIcon icon = MyTreeRenderer.createImageIcon("/com/airties/atof/gui/mvc/utilities/images/testdesign/backward.png");
        removeOperationButton.setIcon(icon);
        removeOperationButton.setEnabled(false);
        removeOperationButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeOperationButtonActionPerformed(evt);
            }
        });

        icon = MyTreeRenderer.createImageIcon("/com/airties/atof/gui/mvc/utilities/images/testdesign/forward.png");
        addOperationsButton.setIcon(icon);
        addOperationsButton.setAlignmentY(0.0F);
        addOperationsButton.setAutoscrolls(true);
        addOperationsButton.setEnabled(false);
        addOperationsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addOperationsButtonActionPerformed(evt);
            }
        });

        propertyPane.setEditable(false);
        jScrollPane3.setViewportView(propertyPane);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(singleModeButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(multipleModeButton, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)
                        .addGap(26, 26, 26)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jRadioButton1)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jRadioButton2)))
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
            .addComponent(addOperationsButton, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
            .addComponent(removeOperationButton, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(addOperationsButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(removeOperationButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(multipleModeButton)
                    .addComponent(jRadioButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(singleModeButton)
                    .addComponent(jRadioButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jSplitPane2.setLeftComponent(jPanel2);

        destinationTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        destinationTree.putClientProperty("JTree.lineStyle", "Angled");
        destinationTree.setCellRenderer(new MyTreeRenderer());
        destinationTree.setRootVisible(false);
        destinationTree.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                destinationTreeMouseClicked(evt);
            }
        });
        destinationTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                destinationTreeValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(destinationTree);

        jLabel2.setText("jLabel2"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE))
        );

        jSplitPane2.setRightComponent(jPanel3);

        jSplitPane1.setRightComponent(jSplitPane2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 853, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 528, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-861)/2, (screenSize.height-562)/2, 861, 562);
    }// </editor-fold>//GEN-END:initComponents

    private void sourceTreeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sourceTreeMouseClicked
        if (evt.getButton() == MouseEvent.BUTTON3) {
            TreePath path = sourceTree.getPathForLocation(evt.getX(),
                    evt.getY());
            sourceTree.setSelectionPath(path);
            ComparisonTreeNode node =
                    (ComparisonTreeNode) sourceTree.getLastSelectedPathComponent();
            TestDesignControllerList.newInstance().getCompareGUIController().
                    operationSelectSourceNode(node);
        } else if (evt.getButton() == MouseEvent.BUTTON1) {
            ComparisonTreeNode node =
                    (ComparisonTreeNode) sourceTree.getLastSelectedPathComponent();
            int x = evt.getX();
            int y = evt.getY();
            int row = sourceTree.getRowForLocation(x,
                    y);
            TreePath path = sourceTree.getPathForRow(row);
            if (path != null && node != null) {
                if (evt.getX() > sourceTree.getPathBounds(path).x + 21) {
                    return;
                }
                boolean isSelected = !(node.isSelected());
                node.setSelected(isSelected);
                node.setSelectedSingle(isSelected);
                if (isSelected) {
                    sourceTree.expandPath(path);
                } else {
                    sourceTree.collapsePath(path);
                }
                sourceTree.revalidate();
            }
        }
}//GEN-LAST:event_sourceTreeMouseClicked

    private void sourceTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_sourceTreeValueChanged
        ComparisonTreeNode node =
                (ComparisonTreeNode) sourceTree.getLastSelectedPathComponent();
        TestDesignControllerList.newInstance().getCompareGUIController().
                operationSelectSourceNode(node);
}//GEN-LAST:event_sourceTreeValueChanged

    private void destinationTreeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_destinationTreeMouseClicked
        if (evt.getButton() == MouseEvent.BUTTON3) {
            TreePath path = destinationTree.getPathForLocation(evt.getX(),
                    evt.getY());
            destinationTree.setSelectionPath(path);
            ComparisonTreeNode node =
                    (ComparisonTreeNode) destinationTree.getLastSelectedPathComponent();
            TestDesignControllerList.newInstance().getCompareGUIController().
                    operationSelectDestinationNode(node);
        } else if (evt.getButton() == MouseEvent.BUTTON1) {
            ComparisonTreeNode node =
                    (ComparisonTreeNode) destinationTree.getLastSelectedPathComponent();
            int x = evt.getX();
            int y = evt.getY();
            int row = destinationTree.getRowForLocation(x,
                    y);
            TreePath path = destinationTree.getPathForRow(row);
            if (path != null && node != null) {
                if (evt.getX() > destinationTree.getPathBounds(path).x + 21) {
                    return;
                }
                boolean isSelected = !(node.isSelected());
                node.setSelected(isSelected);
                node.setSelectedSingle(isSelected);
                if (isSelected) {
                    destinationTree.expandPath(path);
                } else {
                    destinationTree.collapsePath(path);
                }
                destinationTree.revalidate();
            }
        }
}//GEN-LAST:event_destinationTreeMouseClicked

    private void destinationTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_destinationTreeValueChanged
        ComparisonTreeNode node =
                (ComparisonTreeNode) destinationTree.getLastSelectedPathComponent();
        TestDesignControllerList.newInstance().getCompareGUIController().
                operationSelectDestinationNode(node);
}//GEN-LAST:event_destinationTreeValueChanged

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
        if (!jRadioButton1.isSelected()) {
            jRadioButton1.setSelected(true);
        } else {
            jRadioButton2.setSelected(false);
            TestDesignControllerList.newInstance().getCompareGUIController().
                    operationSelectedMode(CompareGUIController.CLONE);
        }
    }//GEN-LAST:event_jRadioButton1ActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
        if (!jRadioButton2.isSelected()) {
            jRadioButton2.setSelected(true);
        } else {
            jRadioButton1.setSelected(false);
            TestDesignControllerList.newInstance().getCompareGUIController().
                    operationSelectedMode(CompareGUIController.COPY);
        }
    }//GEN-LAST:event_jRadioButton2ActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        WindowListener[] listeners = getWindowListeners();
        TestDesignControllerList.newInstance().getCompareGUIController().
                preCloseOperations();
        for (int i = 0; i < listeners.length; i++) {
            removeWindowListener(listeners[i]);
        }
        setEnabled(false);
        TestDesignControllerList.newInstance().getCompareGUIController().
                operationCloseWindow();
        dispose();
    }//GEN-LAST:event_formWindowClosed

    private void addOperationsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addOperationsButtonActionPerformed
        TestDesignControllerList.newInstance().getCompareGUIController().
                addOperations();
}//GEN-LAST:event_addOperationsButtonActionPerformed

    private void removeOperationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeOperationButtonActionPerformed
        TestDesignControllerList.newInstance().getCompareGUIController().
                removeOperation();
        removeOperationButton.setEnabled(false);
}//GEN-LAST:event_removeOperationButtonActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        TestDesignControllerList.newInstance().getCompareGUIController().clickOk();
        dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void singleModeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_singleModeButtonActionPerformed
        if (!singleModeButton.isSelected()) {
            singleModeButton.setSelected(true);
        } else {
            multipleModeButton.setSelected(false);
            TestDesignControllerList.newInstance().getCompareGUIController().
                    operationSetSingleMode(true);
        }
}//GEN-LAST:event_singleModeButtonActionPerformed

    private void multipleModeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleModeButtonActionPerformed
        if (!multipleModeButton.isSelected()) {
            multipleModeButton.setSelected(true);
        } else {
            singleModeButton.setSelected(false);
            TestDesignControllerList.newInstance().getCompareGUIController().
                    operationSetSingleMode(false);
        }
    }//GEN-LAST:event_multipleModeButtonActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    setEnabled(false);
    TestDesignControllerList.newInstance().getCompareGUIController().
            operationCloseWindow();
    dispose();
}//GEN-LAST:event_jButton3ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addOperationsButton;
    private javax.swing.JTree destinationTree;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JRadioButton multipleModeButton;
    private javax.swing.JTextPane propertyPane;
    private javax.swing.JButton removeOperationButton;
    private javax.swing.JRadioButton singleModeButton;
    private javax.swing.JTree sourceTree;
    // End of variables declaration//GEN-END:variables

    public void expandAll(JTree tree,
            boolean expand) {
        MyDefaultMutableTreeNode root = (MyDefaultMutableTreeNode) tree.getModel().
                getRoot();

        // Traverse tree from root
        expandAll(tree,
                new TreePath(root),
                expand);
    }

    private void expandAll(JTree tree,
            TreePath parent,
            boolean expand) {
        // Traverse children
        MyDefaultMutableTreeNode node = (MyDefaultMutableTreeNode) parent.getLastPathComponent();
        if (node.getChildCount() >= 0) {
            for (Enumeration e = node.children(); e.hasMoreElements();) {
                MyDefaultMutableTreeNode n = (MyDefaultMutableTreeNode) e.nextElement();
                TreePath path = parent.pathByAddingChild(n);
                expandAll(tree,
                        path,
                        expand);
            }
        }
        // Expansion or collapse must be done bottom-up
        if (expand) {
            tree.expandPath(parent);
        } else {
            tree.collapsePath(parent);
        }
    }

    @Override
    public void modelPropertyChange(PropertyChangeEvent evt) {
        //System.out.println(evt.getPropertyName());
        if (evt.getPropertyName().equals(CompareGUIController.SOURCE)) {
            ComparisonTreeNode node =
                    (ComparisonTreeNode) evt.getNewValue();
            m_sourceRoot.add(node);
        } else if (evt.getPropertyName().equals(CompareGUIController.DESTINATION)) {
            ComparisonTreeNode node =
                    (ComparisonTreeNode) evt.getNewValue();
            m_destinationRoot.add(node);
        } else if (evt.getPropertyName().equals(
                CompareGUIController.HIGHLIGHT_NODE)) {
            MyDefaultMutableTreeNode node = (MyDefaultMutableTreeNode) evt.getNewValue();
            node.setHighlighted(true);
        } else if (evt.getPropertyName().equals(
                CompareGUIController.UN_HIGHLIGHT_NODE)) {
            MyDefaultMutableTreeNode node = (MyDefaultMutableTreeNode) evt.getNewValue();
            node.setHighlighted(false);
        } else if (evt.getPropertyName().equals(CompareGUIController.ADD_OPERATION)) {
            ComparisonTreeNode node = (ComparisonTreeNode) evt.getNewValue();
            TreePath path = new TreePath(node.getParent().getPath());
            destinationTree.expandPath(path);
        } else if (evt.getPropertyName().equals(
                CompareGUIController.REMOVE_OPERATION)) {
        } else if (evt.getPropertyName().equals(CompareGUIController.PROPERTIES)) {
            propertyPane.setText(evt.getNewValue().toString());
            if (!((String) evt.getNewValue()).equals("")) {
                propertyPane.getVisibleRect().setSize(propertyPane.getX(),
                        0);
                propertyPane.updateUI();
            }
        } else if (evt.getPropertyName().equals(
                CompareGUIController.SRC_TREE_SRC_REFRESH)) {
            sourceTree.updateUI();
        } else if (evt.getPropertyName().equals(
                CompareGUIController.DST_TREE_REFRESH)) {
            destinationTree.updateUI();
        } else if (evt.getPropertyName().equals(
                CompareGUIController.SELECT_SOURCE_NODE)) {
            ComparisonTreeNode node =
                    (ComparisonTreeNode) evt.getNewValue();
            if (node != null) {
                TreePath treePath = new TreePath(node.getPath());
                sourceTree.setSelectionPath(treePath);
                destinationTree.clearSelection();
                if (node.getOperations().size() > 0) {
//                if (node.getColor() != ComparisonTreeNode.EXACT && node.getColor() != ComparisonTreeNode.DIFF_NAME) {
                    addOperationsButton.setEnabled(true);
                } else {
                    addOperationsButton.setEnabled(false);
                }
                removeOperationButton.setEnabled(false);
                destinationTree.repaint();
            }
        } else if (evt.getPropertyName().equals(
                CompareGUIController.SELECT_DESTINATION_NODE)) {
            ComparisonTreeNode node =
                    (ComparisonTreeNode) evt.getNewValue();
            if (node != null) {
                TreePath treePath = new TreePath(node.getPath());
                destinationTree.setSelectionPath(treePath);
                sourceTree.clearSelection();
//                if (node.getSelectedOperations().size()>0) {
                if (node.getColor() == ComparisonTreeNode.COMPARE) {
                    removeOperationButton.setEnabled(true);
                } else {
                    removeOperationButton.setEnabled(false);
                }
                addOperationsButton.setEnabled(false);
                sourceTree.repaint();
            }
        } else if (evt.getPropertyName().equals(CompareGUIController.SRC_LABEL)) {
            jLabel1.setText(evt.getNewValue().toString());
        } else if (evt.getPropertyName().equals(CompareGUIController.DST_LABEL)) {
            jLabel2.setText(evt.getNewValue().toString());
        } else if (evt.getPropertyName().equals(CompareGUIController.SHOW)) {
            expandAll(sourceTree, true);
            expandAll(destinationTree, true);
            this.centerParent();
        }
    }
}
